﻿/*

******************************************************

CreateDate  *  Author         *  Content

2008-1-17   *  donne.yang     *  Bind Control From DataSet
******************************************************

version     update date     update by      description

*********************************************************

*/
using System;
using System.Data;
using System.Collections;
using System.Data.OracleClient;
using System.Web.UI.WebControls;

namespace Stc.Web
{
    class BindControl
    {
        public BindControl()
        { 
        }

        /// <summary>
        /// 将DataSet中Tables[0]的数据绑定给DropDownList
        /// </summary>
        /// <param name="ddl">待绑定的DropDownList</param>
        /// <param name="strName">绑定DropDownList的Text值在DataSet的字段名称</param>
        /// <param name="strValue">绑定DropDownList的Value值在DataSet的字段名称</param>
        /// <param name="ds">DataSet</param>
        public void BindControlFromDataSet(DropDownList ddl, string strName, string strValue, DataSet ds)
        {
            try
            {
                if (ds != null && ds.Tables.Count > 0)
                {
                    if (ddl != null && ds.Tables[0].Rows.Count > 0) //dropdownlist
                    {
                        ddl.DataSource = ds.Tables[0].DefaultView;
                        ddl.DataTextField = strName;
                        ddl.DataValueField = strValue;
                        ddl.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;		
            }
            finally
            {
            }
        }

        /// <summary>
        /// 将DataSet中Tables[0]的数据绑定给CheckBoxList.
        /// </summary>
        /// <param name="cbl">待绑定的CheckBoxList</param>
        /// <param name="strName">绑定CheckBoxList的Text值在DataSet的字段名称</param>
        /// <param name="strValue">绑定CheckBoxList的Value值在DataSet的字段名称</param>
        /// <param name="ds">DataSet</param>
        public void BindControlFromDataSet(CheckBoxList cbl, string strName, string strValue, DataSet ds)
        {
            try
            {
                if (ds != null && ds.Tables.Count > 0)
                {
                    if (cbl != null && ds.Tables[0].Rows.Count > 0) //CheckBoxList
                    {
                        cbl.DataSource = ds.Tables[0].DefaultView;
                        cbl.DataTextField = strName;
                        cbl.DataValueField = strValue;
                        cbl.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;		
            }
            finally
            {
            }
        }

        /// <summary>
        /// 将DataSet中Tables[0]的数据绑定给RadioButtonList.
        /// </summary>
        /// <param name="cbl">待绑定的RadioButtonList</param>
        /// <param name="strName">绑定RadioButtonList的Text值在DataSet的字段名称</param>
        /// <param name="strValue">绑定RadioButtonList的Value值在DataSet的字段名称</param>
        /// <param name="ds">DataSet</param>
        public void BindControlFromDataSet(RadioButtonList rbl, string strName, string strValue, DataSet ds)
        {
            try
            {
                if (ds != null && ds.Tables.Count > 0)
                {
                    if (rbl != null && ds.Tables[0].Rows.Count > 0) //RadioButtonList
                    {
                        rbl.DataSource = ds.Tables[0].DefaultView;
                        rbl.DataTextField = strName;
                        rbl.DataValueField = strValue;
                        rbl.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;			
            }
            finally
            {
            }
        }

        /// <summary>
        /// 将DataSet中Tables[0]的数据绑定给BulletedList.
        /// </summary>
        /// <param name="cbl">待绑定的BulletedList</param>
        /// <param name="strName">绑定BulletedList的Text值在DataSet的字段名称</param>
        /// <param name="strValue">绑定BulletedList的Value值在DataSet的字段名称</param>
        /// <param name="ds">DataSet</param>
        public void BindControlFromDataSet(BulletedList bl, string strName, string strValue, DataSet ds)
        {
            try
            {
                if (ds != null && ds.Tables.Count > 0)
                {
                    if (bl != null && ds.Tables[0].Rows.Count > 0) //BulletedList
                    {
                        bl.DataSource = ds.Tables[0].DefaultView;
                        bl.DataTextField = strName;
                        bl.DataValueField = strValue;
                        bl.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;	
            }
            finally
            {
            }
        }
    }
}
